package lzk.myshop.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lzk.myshop.pojo.Classify;
import lzk.myshop.pojo.Goods;
import lzk.myshop.pojo.Merchant;
import lzk.myshop.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/Mer")
@RestController
@Api("Mer interface")
@CrossOrigin(origins = "*")
public class MerchantController {
    @Autowired
    MerchantService merchantService;

    @ApiOperation("商家登录接口,需要账号（邮箱/手机号）密码")
    @GetMapping("/signIn")
    public Map<String,Object> signIn(String account,String password){
        return merchantService.signIn(account,password);
    }

    @ApiOperation("返回店铺中所有的商品对象集合,需要传入商家id")
    @GetMapping("/allGoods")
    public Map<String,Object> allGoods(int merId){
        return merchantService.goodsOfMer(merId);
    }

    @ApiOperation("新增商品,需要商家id，分类名称，商品名字，介绍，价格（double类型），数量，图片")
    @PostMapping("/addGoods")
    public Map<String,Object> addGoods(Goods goods){
        return merchantService.addGoods(goods);
    }

    @ApiOperation("修改商品信息,需要商家id，分类名称，商品名字，介绍，价格（double类型），数量，图片")
    @PostMapping("/alterGoods")
    public Map<String,Object> alterGoods(Goods goods){
        return merchantService.alterGoods(goods);
    }

    @ApiOperation("下架商品,需要商品id")
    @DeleteMapping("/deleteGoods")
    public Map<String,Object> deleteGoods(int id){
        return merchantService.downGoods(id);
    }

    @ApiOperation("查看所有的分类名称,需要商家id")
    @GetMapping("/allClassify")
    public Map<String,Object> allClassify(int merID){
        return merchantService.allClassify(merID);
    }

    @ApiOperation("添加商品分类,需要商家id和分类名称")
    @PostMapping("/addClassify")
    public Map<String,Object> addClassify(Classify classify){
        return merchantService.addClassify(classify);
    }

    @ApiOperation("删除商品分类,需要分类的id")
    @DeleteMapping("deleteClassify")
    public Map<String,Object> deleteClassify(int id){
        return merchantService.deleteClassify(id);
    }

    @ApiOperation("查看所有订单,需要商家的id")
    @GetMapping("getAllOrders")
    public Map<String,Object> getAllOrders(int merchantId){
        return merchantService.getAllMerOrders(merchantId);
    }

//    @ApiOperation("查询订单")
//    @GetMapping("/searchOrderByID")
//    public Map<String,Object> searchOrderByID(){
//        return null;
//    }

    @ApiOperation("发货，需要订单id")
    @PostMapping("/sendGoods")
    public Map<String,Object> sendGoods(int Orderid){
        return merchantService.sentGoods(Orderid);
    }

    @ApiOperation("店铺注销")
    @DeleteMapping("/deleteMer")
    public Map<String,Object> deleteMer(int id){
        return merchantService.deleteMer(id);
    }
}
